home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0135_Virtual world plotting.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-25  |  5KB  |  97 lines

  1. {
  2. From: yliu@morgan.ucs.mun.ca (Yuan Liu)
  3.  
  4. : I have a question for drawing a graphic.  I have a set of data.
  5. : I want to read these data and plot them in the XY axes.  Does anyone
  6. : know how to caculate the data to fit the X axis.  I am using TP 7.0.
  7.  
  8. When converting from HP Pascal, which provides a nice subset of the
  9. device-independent graphics kernal and allows plotting in the virtual world
  10. (so the window and viewport can be set in the virtual world), I wrote
  11. several procedures to simulate virtual world plotting.  The following is
  12. part of a unit Plotbase I created.
  13.  
  14. The function you needed is set_window; the boolean pagefit controls
  15. whether you just want your plot to fit in the whole window or there's a concern
  16. about the isotropy of the plot.  I didn't bother to write a virtual
  17. world set_viewport as I can live without it.
  18.  
  19. }
  20. UNIT PLOTBASE; {******************* Stored in 'PLOTBASE' ******************}
  21. {*     Basic procedures for graphical manipulations.                      *}
  22. {*     Created in 1983.  Updated 17/05/94 10:00 a.m.       By LIU Yuan    *}
  23. {**************************************************************************}
  24. interface USES Graph;
  25. procedure set_window(left, right, up, down: extended; pagefit: boolean);
  26.          {Sets a mapping of virtual window on the current viewport;
  27.            use isotropic scaling if not pagefit.}
  28. function vToX(x: extended): integer;
  29. function vToY(y: extended): integer;
  30.          {Map x, y in the virtual world onto real world}
  31. function XtoV(X: integer): extended;
  32. function YtoV(Y: integer): extended;
  33.          {Maps X, Y in the real world onto virtual world}
  34.            use isotropic scaling if not pagefit.
  35. procedure vMove(x, y: extended);
  36.           {Moves the current position to (x,y) in the virtual world}
  37. procedure vMoveRel(Dx, Dy: extended);
  38. {Moves the current position a relative distance in the virtual world}
  39. procedure vLine(x1, y1, x2, y2: extended);
  40.           {Draws a line from (x1,y1) to (x2,y2) in the virtual world}
  41. procedure vLineTo(x, y: extended);
  42.           {Draws a line from current position to (x,y) in the virtual world}
  43. function str_width(str: string): extended; {string width in the virtual world}
  44. function str_height(str: string): extended; {string height in the virtual
  45. world}
  46. implementation {************************** PLOTBASE *************************}
  47.         var Text:         string[20];
  48.             xasp, yasp, xbase, ybase: extended;
  49.             {convert from virtual world to display}
  50.  
  51. procedure set_window(left, right, up, down: extended; pagefit: boolean);
  52.          {Sets a mapping of virtual window on the current viewport;
  53.            use isotropic scaling if not pagefit.
  54.            Side effects: xasp, yasp, xbase, ybase.}
  55. var view: ViewPortType;
  56. begin xbase:=left; ybase:=down; right:=right-left; up:=up-down;
  57.       GetViewSettings(view);
  58.       right:=(view.x2-view.x1)/right;
  59.       up:=(view.y2-view.y1)/up;
  60.       if pagefit then begin xasp:=right; yasp:=up end
  61.       else if right<up then begin yasp:=right; xasp:=right; end
  62.                        else begin xasp:=up; yasp:=up end
  63. end; {set_window}
  64.  
  65. function vToX(x: extended): integer;begin vToX:=round((x-xbase)*xasp) end;
  66.          {Maps x in the virtual world onto real world}
  67. function vToY(y: extended): integer;begin vToY:=round((y-ybase)*yasp) end;
  68.          {Maps x in the virtual world onto real world}
  69.  
  70. function XtoV(X: integer): extended; begin XtoV:=X/xasp+xbase end; {XtoV}
  71.          {Maps X in the real world onto virtual world}
  72. function YtoV(Y: integer): extended; begin YtoV:=Y/yasp+ybase end; {YtoV}
  73.          {Maps Y in the real world onto virtual world}
  74.  
  75. procedure vMove(x, y: extended);
  76.           {Moves the current position to (x,y) in the virtual world}
  77. begin MoveTo(round((x-xbase)*xasp),round((y-ybase)*yasp)) end; {vMove}
  78. procedure vMoveRel(Dx, Dy: extended);
  79. {Moves the current position a relative distance in the virtual world}
  80. begin MoveRel(round(Dx*xasp),round(Dy*yasp)) end; {vMoveRel}
  81.  
  82. procedure vLine(x1, y1, x2, y2: extended);
  83.           {Draws a line from (x1,y1) to (x2,y2) in the virtual world}
  84. begin line(round((x1-xbase)*xasp),round((y1-ybase)*yasp),
  85.            round((x2-xbase)*xasp),round((y2-ybase)*yasp)) end; {vLine}
  86.  
  87. procedure vLineTo(x, y: extended);
  88.           {Draws a line from current position to (x,y) in the virtual world}
  89. begin LineTo(round((x-xbase)*xasp),round((y-ybase)*yasp)) end; {vLineTo}
  90.  
  91. function str_width(str: string): extended; {string width in the virtual world}
  92. begin str_width:=TextWidth(str)/xasp end; {str_width}
  93.  
  94. function str_height(str: string): extended; {string height in the virtual
  95. world}
  96. begin str_height:=TextHeight(str)/yasp end; {str_height}
  97.